<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URI"%>
<%@page import="cn.jekun.component.base.spring.SpringUtils"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="cn.jekun.shop.web.service.ShopService"%>
<%@page import="cn.jekun.component.core.service.ConfigService"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
	contentType="text/html; charset=UTF-8"%>
<%@ include file="/v1/pages/public/taglibs.jsp"%>
<%@page import="cn.jekun.shop.web.bean.MemberSession"%>
<%!
private static String utf8Togb2312(String str){
    StringBuffer sb = new StringBuffer();
    for(int i=0; i<str.length(); i++) {
        char c = str.charAt(i);
        switch (c) {
           case '+':
               sb.append(' ');
           break;
           case '%':
               try {
                    sb.append((char)Integer.parseInt(
                    str.substring(i+1,i+3),16));
               }
               catch (NumberFormatException e) {
                   throw new IllegalArgumentException();
              }
              i += 2;
              break;
           default:
              sb.append(c);
              break;
         }
    }
    // Undo conversion to external encoding
    String result = sb.toString();
    String res=null;
    try{
        byte[] inputBytes = result.getBytes("8859_1");
        res= new String(inputBytes,"UTF-8");
    }
    catch(Exception e){}
    return res;
} 
%>
<%


	String[] mobileAgents = { "iphone", "android", "phone", "mobile", "wap", "netfront", "java", "opera mobi",
	"opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod",
	"nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma",
	"docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos",
	"techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem",
	"wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos",
	"pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320",
	"240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac",
	"blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs",
	"kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi",
	"mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port",
	"prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem",
	"smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v",
	"voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-",
	"Googlebot-Mobile" };
	if (request.getHeader("User-Agent") != null) {
		for (String mobileAgent : mobileAgents) {
			if (request.getHeader("User-Agent").toLowerCase().indexOf(mobileAgent) >= 0) {
		
				String shopId=request.getParameter("shopId");
				String params="";
				if(shopId==null && request.getQueryString()!=null){
					params= (java.net.URLDecoder.decode(request.getQueryString(),"utf-8"));  
					//params=utf8Togb2312(params);
					params=params.replaceAll("#","");
					params=params.replaceAll("%","");
					
					if(params.indexOf("shopId")>=0){
						
						if(params.indexOf("&")>=0){
							
							params=params.split("&")[0];
							
						}
						
						shopId=params.split("=")[1];
					}
					
					
				}
				
				if(!StringUtils.isBlank(shopId)){
					
					//response.sendRedirect(request.getContextPath()+"/v1/h5/pages/index.jsp?shopId="+shopId+"#ldhStore");
					response.sendRedirect(request.getContextPath()+"/h5/shopIndex/"+shopId+".shtml");
				}else{
					
					//response.sendRedirect(request.getContextPath()+"/v1/h5/pages/index.jsp");
					
					response.sendRedirect(request.getContextPath()+"/h5/index.shtml");
				}
				break;
				}
		}
	}
	

	//文件服务器
	pageContext.setAttribute("FILE_U_URL",
	cn.jekun.component.core.service.ConfigService
	.getFileUploadUrl());
	pageContext.setAttribute(
	"FILE_O_URL",
	cn.jekun.component.core.service.ConfigService
	.getFileOpenUrl() + "/200");
	pageContext.setAttribute("FILE_O_S_URL",
	cn.jekun.component.core.service.ConfigService
	.getFileOpenUrl());
	pageContext.setAttribute("FILE_D_URL",
	cn.jekun.component.core.service.ConfigService
	.getFileDownloadUrl());
	
	
	String host = request.getHeader("Host").trim();
	
	String[] hosts = host.split("[.]");
	
	//判断其它域名不能指向到该地址
	if(hosts.length == 3){
		
		if(host.indexOf("jujie.xyz")< 0 &&  host.indexOf("storeme.cn")<0){
	
	
	response.sendRedirect("http://www.storeme.cn");
	
	return;
		}
		
	}
	
	
	if (host.indexOf("jujie.xyz") >= 0) {

		
		if (hosts.length == 3
		&& request.getRequestURL().indexOf("shopIndex") < 0) {//只处理长度为3的信息 并且当前页面不是商家主页
	if ("jujie".equals(hosts[1]) && "xyz:8082".equals(hosts[2])) {//判断是否是jujie.xyz.com的2级域名  
		String name = hosts[0].trim();
		if (!"www".equals(name) && name != null) {

			ShopService service = SpringUtils
					.getBean(ShopService.BEAN_NAME);

			JSONObject jsonObject = service
					.isShopExits(hosts[0]);

			if (jsonObject.getString("isExits").equals("true")) {
										
				response.sendRedirect("http://"
						+ hosts[0]
						+ ".jujie.xyz:8082/mall/v1/pages/shop/shopIndex.jsp");
			} else {

				response.sendRedirect("http://www.jujie.xyz:8082/mall/v1/pages/404.jsp");
			}
			return;
		} else {

			hosts[0] = null;
		}
	}
		} else {
	//hosts.length==4 表示Ip来访问的
	//hosts.length==2 表示可能是jujie.xyz来访问的
	if (hosts.length == 4 || hosts[0].equals("www")
			|| hosts.length == 2) {
		hosts[0] = null;
	}else{
		
		//防止随意修改URL导致访问不了
		ShopService service = SpringUtils
				.getBean(ShopService.BEAN_NAME);

		JSONObject jsonObject = service
				.isShopExits(hosts[0]);
		
		if (jsonObject.getString("isExits").equals("true")) {
			
			hosts[0]=jsonObject.getString("shopId");
					
		} else {
 
			response.sendRedirect("http://www.jujie.xyz:8082/mall/v1/pages/404.jsp"); 
		}
		
	}

		}

	} else if (host.indexOf("storeme.cn") >= 0) {

		if (hosts.length == 3
		&& request.getRequestURL().indexOf("shopIndex") < 0) {//只处理长度为3的信息 并且当前页面不是商家主页
	if ("lindianhui".equals(hosts[1]) && "com".equals(hosts[2])) {//判断是否是jujie.xyz.com的2级域名  
		String name = hosts[0].trim();
		if (!"www".equals(name) && name != null) {

			ShopService service = SpringUtils
					.getBean(ShopService.BEAN_NAME);

			JSONObject jsonObject = service
					.isShopExits(hosts[0]);
			
			if (jsonObject.getString("isExits").equals("true")) {
				
				//hosts[0]=jsonObject.getString("shopId");
						
				response.sendRedirect("http://"
						+ hosts[0]
						+ ".storeme.cn/mall/v1/pages/shop/shopIndex.jsp");
			} else {

				response.sendRedirect("http://www.storeme.cn/mall/v1/pages/404.jsp");
			}
			return;
		} else {

			hosts[0] = null;
		}
	}
		} else {
	//hosts.length==4 表示Ip来访问的
	//hosts.length==2 表示可能是 storeme.cn来访问的
	if (hosts.length == 4 || hosts[0].equals("www")
			|| hosts.length == 2) {
		hosts[0] = null;
	}else{
		
		//防止随意修改URL导致访问不了
		ShopService service = SpringUtils
				.getBean(ShopService.BEAN_NAME);

		JSONObject jsonObject = service
				.isShopExits(hosts[0]);
		
		if (jsonObject.getString("isExits").equals("true")) {
			
			hosts[0]=jsonObject.getString("shopId");
					
		} else {
 
			response.sendRedirect("http://www.storeme.cn/mall/v1/pages/404.jsp");
		}
		
	}
	
	

		}
	}else{
		
		hosts[0] = null;
	}
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>云便利商店</title>
<!--[if IE 8]>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<![endif]-->
<meta title="云便利商店APP，您身边的淘宝，快速、便捷的社区生活购物平台"/>
<meta name="keywords" content="提供超市、便利店、生鲜食品、粮油副食、零食小吃、餐饮外卖等网购送货，以及小区家政服务、跑腿配送、快递物流等预约上门。" />
<meta name="description" content="云便利商店APP，您身边的淘宝。它囊括了您身边的超市、便利店、食店、生鲜店、家政服务等各种社区生活服务商家，走到哪里都可以帮您精准找到身边的店铺，为您提供近距离、快速送货的轻松购物体验。" />
<link rel="shortcut icon" type="img/x-icon"
	href="${ctx}/v1/img/favicon.ico" />
<link rel="stylesheet" type="text/css"
	href="${ctx}/v1/css/ldh.style.css" />

<script language="javascript" src="${ctx}/v1/js/default/jquery.min.js"
	type="text/javascript"></script>
<script language="javascript" src="${ctx}/v1/js/default/sea.js"
	type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="${ctx}/v1/js/default/js/html5shiv.js"></script>
<![endif]-->
<!--[if lte IE 6]>
<script src="${ctx}/v1/js/default/ie6_visit.js" type="text/javascript" charset="gb2312"></script>
<![endif]-->
<script type="text/javascript">
	var host="";
    if(document.URL.indexOf("http://www.storeme.cn")>=0){
    	
    	host ="http://www.storeme.cn";
    }
	if(document.URL.indexOf("http://www.storeme.cn")>=0){
    	
    	host ="http://www.storeme.cn";
    }
  	if(document.URL.indexOf("http://www.jujie.xyz")>=0){
    	
    	host ="http://www.jujie.xyz";
    }
	if(document.URL.indexOf("http://jujie.xyz")>=0){
    	
    	host ="http://jujie.xyz";
    }
    
	var ctx ="${ctx}";
	//文件上传服务器head.jsp
	var fileUploadUrl = '${FILE_U_URL}';
	//文件下载服务器
	var fileDownUrl = '${FILE_D_URL}';
	//在线打开服务器
	var fileOpenUrl = '${FILE_O_URL}';
	//在线打开原图片文件
	var fileOpenSourceUrl = '${FILE_O_S_URL}';
	
/* 	var fileUploadUrl = 'http://192.168.88.6:5555/file/u';
	//文件下载服务器
	var fileDownUrl = 'http://192.168.88.6:5555/file/d';
	//在线打开服务器
	var fileOpenUrl = 'http://192.168.88.6:5555/file/f/200';
	//在线打开原图片文件
	var fileOpenSourceUrl = 'http://192.168.88.6:5555/file/f'; */

</script>
</head>
<!-- 当前登录用户信息 -->
<input type="hidden" id="session_userid" value="${sessionScope._SESSION_USER_.userId}"/>
<input type="hidden" id="session_username" value="${sessionScope._SESSION_USER_.userName}"/>
<input type="hidden" id="session_iconurl" value="${sessionScope._SESSION_USER_.iconUrl}"/>
<input type="hidden" id="session_shopid" value="${sessionScope._SESSION_USER_.shopId}"/>
<input type="hidden" id="session_agentId" value="${sessionScope._SESSION_USER_.agentId}"/>
<input type="hidden" id="session_agentName" value="${sessionScope._SESSION_USER_.agentName}"/>

<!-- 搜索类型  -->
<input type="hidden" id="search_type" value="${param.searchType}"/>
<!-- 弹出框 start-->
<div class="ldh-loginBox">
	<!-- 登录框  -->
	<div class="ldh-loginDiv" id="ldh-loginDiv">
    	<div class="ldh-logHeader">
    	    <h2><span>登录</span><a class="fl-right" href="javascript:$ldh_base.forgotShow()">忘记密码</a></h2>
<!--             <h2>登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:$ldh_base.registerShow()">注册</a></h2>
 -->            <p class="ldh-logTips text-right" id="tip_login"></p>
        </div>
        <ul class="ldh-inputBox">
            <li><input type="text" class="ldh-logInput" placeholder="手机号码" id="login_mobile"/></li>
            <li><input type="password" class="ldh-logInput" placeholder="密码" id="login_password"/></li>           
        </ul>
        <div class="ldh-logBtnDiv clearfix"><button type="button" class="ldh-forgetBtn" onClick="$ldh_base.registerShow()">注册</button><button type="button" class="ldh-logBtn" id="btn_login" onclick="$ldh_base.login()">登录</button></div>
        <div class="ldh-remember" style="display:none;"><span class="ldh-remText">记住密码</span><span class="ldh-logCheckbox checked" onclick="$ldh_base.remember(this)"><input type="checkbox" class="opacity_0"/></span></div>
    </div>
    <!-- 注册框  -->
    <div class="ldh-loginDiv" id="ldh-register">
    	<div class="ldh-logHeader">
            <h2>注册</h2>
            <p class="ldh-logTips text-right" id="tip_register"></p>
        </div>
        <ul class="ldh-inputBox">
            <li><input type="text" class="ldh-logInput" placeholder="手机号码" id="mobile" /></li>
            <li class="clearfix"><input type="text" class="ldh-shortInput" placeholder="输入验证码" id="validateCode"/><button type="button" class="ldh-shortBtn" id="btn_request_code" onclick="$ldh_base.validateMobile('#mobile','#btn_request_code','#tip_register')" style="height:50px;font-size:13px;">免费获取验证码</button></li>
            <li><input type="password" class="ldh-logInput" placeholder="密码" id="password"/></li>           
        </ul>
        <div class="ldh-protocolsLink"><span class="ldh-checkbox-span checked" onclick="$ldh_base.agree(this)"><input type="checkbox" id="cb_agree"  value="1" class="opacity_0"/></span><span>同意</span><a href="${ctx}/registerAgreement.jsp" target="_blank" class="orange">《云便利商店注册协议》</a></div>
        <div class="ldh-logBtnDiv"><button type="button" class="ldh-longBtn" id="btn_register" onclick="$ldh_base.register()">注册</button></div>        
    </div>
    
    <div class="ldh-loginDiv" id="ldh-forgot">   
    	<!-- 找回密码  -->	
        <div class="ldh-findpwd" id="ldh-findpwd">    
            <div class="ldh-logHeader">
                <h2>找回密码</h2>
                <p class="ldh-logTips text-right" id="tip_find"></p>
            </div>
            <ul class="ldh-inputBox">
                <li><input type="text" class="ldh-logInput" placeholder="手机号码" id="find_mobile"/></li>
                <li class="clearfix"><input type="text" class="ldh-shortInput" placeholder="输入验证码"  id="find_validateCode"/><button type="button" class="ldh-shortBtn" id="btn_find_request_code" onclick="$ldh_base.validateMobile('#find_mobile','#btn_find_request_code','#tip_find')" style="height:50px;font-size:13px;" >免费获取验证码</button></li>   
            </ul>
            <div class="ldh-logBtnDiv"><button type="button" class="ldh-longBtn" onClick="$ldh_base.getValidate()" id="btn_find_next">下一步</button></div>               
        </div>
        <!-- 修改密码  -->
        <div class="ldh-changepwd" id="ldh-changepwd">
            <div class="ldh-logHeader">
                <h2>修改密码</h2>
                <p class="ldh-logTips text-right" id="tip_re_pwd"></p>
            </div>
            <ul class="ldh-inputBox">
                <li><input type="password" class="ldh-logInput" placeholder="输入新密码" id="find_password"/></li>     
                <li><input type="password" class="ldh-logInput" placeholder="再次输入密码"  id="find_confirm_password"/></li>      
            </ul>
            <div class="ldh-logBtnDiv"><button type="button" class="ldh-longBtn" onclick="$ldh_base.reLoginPwd()" id="btn_re_pwd">确定</button></div>                 
        </div>
        <div class="ldh-pageTips"><span class="on"></span><span></span></div>  
    </div>
    <div id="ldh-closeX" onClick="$ldh_base.loginBoxClose()">X</div>
</div>
<!-- 登录框  end-->

<!-- 切换地址  start -->
<div class="ldh-location">
	<div id="allmap"></div>
	<div class="ldh-lcTrue">
    	<div class="ldh-adress-box clearfix">
            <div class="ldh-city" id="ldh-city">
                <div class="ldh-ctLabel"><span id="cityName">广州市</span><b class="icon_down"></b></div>
                <div class="ldh-ctGroup">
                	<div class="ldh-nowCity"><span>当前城市：</span><span>广州市</span></div>            	
                    <div class="ldh-ctList">                	
                        <dl>
                        	<!-- <dt><span>已开通城市</span></dt> -->
                            <dd onclick="$ldh_base.setCity('440100','广州市')"><span>广州市</span></dd>
                            <dd onclick="$ldh_base.setCity('440400','珠海市')"><span>珠海市</span></dd>
                            <dd onclick="$ldh_base.setCity('110100','北京市')"><span>北京市</span></dd>
                            <dd onclick="$ldh_base.setCity('431300','娄底市')"><span>娄底市</span></dd>
                        </dl>                 
                    </div>                
                </div>
            </div>
            
            <div class="ldh-addressSearch">
            	<div class="ldh-addressInput">
                	<input id="ldh-inputAdress" type="text" placeholder="输入街道/地标/商圈.例如:广州塔" />
                  <!--  <button type="button" class="ldh-searchBtn"></button> -->
               </div>               
            </div> 
               
            <div class="ldh-addressGroup">
                <ul id="searchLResultList">
                  <!--   <li>天河区天河路240号</li>
                    <li>天河区天河路241号</li>
                    <li>天河区天河路242号</li>
                    <li>天河区天河路243号</li>
                    <li>天河区天河路240号</li>
                    <li>天河区天河路241号</li>
                    <li>天河区天河路242号</li>
                    <li>天河区天河路243号</li> -->
                </ul>
            </div>
            <div class="ldh-adressTips" style="margin-top:20px;">
            	<p>热门推荐：
            	<span onclick="$ldh_base.selectSearchItem('新鸿花园','113.325296','23.110268')">广州市-海珠区-新鸿花园</span>
            	<span onclick="$ldh_base.selectSearchItem('华发新城','113.521635','22.237993')">珠海市-华发新城</span>
            	<span onclick="$ldh_base.selectSearchItem('太古汇','113.338935','23.1400')">广州市-天河区-太古汇</span>
            	<br>
            	<span style="margin-left:90px;" onclick="$ldh_base.selectSearchItem('南浦','113.299986','23.040016')">广州市-海珠区-南浦</span>
            	<span style="margin-left:20px;" onclick="$ldh_base.selectSearchItem('丽江花园','113.307404','23.041919')">广州市-番禺区-丽江花园</span>
            	<span style="margin-left:20px;" onclick="$ldh_base.selectSearchItem('龙洞','113.371876','23.201761')">广州市-天河区-龙洞步行街</span>
            	<br>
            	<span style="margin-left:90px;" onclick="$ldh_base.selectSearchItem('岭南学院','113.423576','23.172541')">广州市-天河区-岭南学院</span>
            	<span style="margin-left:90px;" onclick="$ldh_base.selectSearchItem('日盛商都','111.312132','27.739237')">湖南市-娄底-日盛商都</span>
            	</p>
            	
            	<!-- <p>热门推荐：</p>
            	<ul id="recommendAddress">
                   	<li><span onclick="$ldh_base.selectSearchItem('新鸿花园','113.325296','23.110268')">广州市-海珠区-新鸿花园</span></li>
                   	<li><span onclick="$ldh_base.selectSearchItem('华发新城','113.521635','22.237993')">珠海市-华发新城</span></li>
                   	<li><span onclick="$ldh_base.selectSearchItem('太古汇','113.338935','23.1400')">广州市-天河区-太古汇</span></li>
             
                   	"$ldh_base.selectSearchItem("丰兴广场","113.340371","23.138278")
                </ul>  -->   
            </div>
    	</div>
    </div>
    <div class="ldh-lcShade"></div>
    <div class="ldh-lcBottom"><!--<span>云便利商店</span>--></div>
    <div class="ldh-location-close" id="btn_close_location" style="display:none;" onclick="$ldh_base.myLocationHide()">x</div>
</div>
<!-- 切换地址  end -->

<div id="l-map"></div>